package jianzhi_offer;

import java.util.Stack;

public class _25_二叉搜索树与双向链表 {
    public static void main(String[] args) {
        _25_二叉搜索树与双向链表 test = new _25_二叉搜索树与双向链表();
        TreeNode t10 = new TreeNode(10);
        TreeNode t6 = new TreeNode(6);
        TreeNode t14 = new TreeNode(14);
        t10.left = t6;
        t10.right =t14;
        test.Convert(t10);
    }

    TreeNode now;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null) return null;
        TreeNode fake = new TreeNode(-1);
        now = fake;
        help(pRootOfTree);
        fake =  fake.right;
        fake.left = null;
        return fake;
    }

    public void help(TreeNode root) {
        if(root.left != null) help(root.left);
        now.right = root;
        root.left = now;
        now = root;
        if(root.right != null) help(root.right);
    }
}
